package com.venue.hjt.venueclass.ui

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.WindowManager
import com.google.gson.Gson

import com.venue.hjt.venueclass.R
import com.venue.hjt.venueclass.adapter.VenueGroupAdapter
import com.venue.hjt.venueclass.adapter.VenueXGroupAdapter
import com.venue.hjt.venueclass.bean.API
import com.venue.hjt.venueclass.bean.PersonalBean
import com.venue.hjt.venueclass.bean.StudentBean
import com.venue.hjt.venueclass.bean.VenueGroupBean
import com.venue.hjt.venueclass.utlis.Constant
import com.venue.hjt.venueclass.utlis.OkhttPost
import kotlinx.android.synthetic.main.activity_venue_complaint.*
import kotlinx.android.synthetic.main.activity_venue_group.*
import okhttp3.Call
import java.lang.Exception
import java.util.ArrayList

class VenueGroupActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar!!.hide()
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
        window.setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
        setContentView(R.layout.activity_venue_group)
        Thread(Runnable {
            while (i > 0) {
                handler.sendEmptyMessage(1)
                if (i <= 0) {
                    break
                }
                try {
                    Thread.sleep(1000)
                } catch (e: InterruptedException) {
                    e.printStackTrace()
                }
                i--
            }
            handler.sendEmptyMessage(2)
        }).start()
        iv_group_close1.setOnClickListener({
            i=1
        })
        val id = intent.getStringExtra("id")
        Log.e("ATG",API.VENUEGROUPINFO + Constant.SNO+"/"+id)
        OkhttPost.Okget(API.VENUEGROUPINFO + Constant.SNO+"/"+id, 2, object : OkhttPost.Callback{
            override fun onError(call: Call?, e: Exception?, id: Int) {
            }
            override fun onResponse(response: String?, id: Int) {
                Log.e("ATG",response)
                val gson=Gson()
                val bean = gson.fromJson(response, VenueGroupBean::class.java)
               if(bean.code==1){
                   val data = bean.data
                   tv_group_x_name.text=data.groupname
                   tv_group_description.text=data.description
                   tv_group_x_num.text="成员 "+data.users.size.toString()+"人"
                    val adapter= VenueXGroupAdapter(this@VenueGroupActivity,data.users)
                   gv_group_c.adapter=adapter
                   val adapter1=VenueGroupAdapter(this@VenueGroupActivity,data.bookings)
                   lv_group.adapter=adapter1
               }
            }

        })
    }
    internal var i = 30
    internal var handler: Handler = object : Handler() {
        override fun handleMessage(msg: android.os.Message) {
            if (msg.what == 1) {
//                tv_countdown.text = "还剩" + i + "关闭界面"
                tv_group_close.text="还剩" + i + "关闭界面"
            } else {
                this@VenueGroupActivity.finish()

            }
        }
    }
}
